/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.gob.fonafe.dao.impl.stored;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import oracle.jdbc.OracleTypes;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.StoredProcedure;
import pe.gob.fonafe.domain.SubastaBean;

/**
 *
 * @author czela
 */
public class ListarAsignarSubastaSP extends StoredProcedure{

    private static final String PROC_PARAM="USERGLC.P_OBT_LIST_SUBASTAS";


    public ListarAsignarSubastaSP(DataSource ds) {
        super(ds, PROC_PARAM);

        declareParameter(new SqlParameter("PAR_ID_EMPRESA", Types.NUMERIC));
        declareParameter(new SqlOutParameter("cCursor", OracleTypes.CURSOR,new ListarAsignaSubastaRowMapper()));
        compile();
    }

    public Map execute(int intIDEmpresa){
        Map inputs = new HashMap();
        inputs.put("PAR_ID_EMPRESA", intIDEmpresa);
        return super.execute(inputs);
    }

    private static class ListarAsignaSubastaRowMapper implements RowMapper<SubastaBean>{

        public SubastaBean mapRow(ResultSet rs, int rowNum) throws SQLException {
            SubastaBean bean = new SubastaBean();
            bean.setId(rs.getString("ID_SUBASTA"));
            bean.setNombre(rs.getString("NOMBRE"));
            bean.setFechCreacion(rs.getDate("FECHA_CREACION"));
            bean.setFechVencimiento(rs.getDate("FECHA_VENCIMIENTO"));
            bean.setTipo(rs.getString("TIPOSUBASTA"));
            bean.setIdTipo(rs.getString("IDTIPOSUBASTA"));
            bean.setClase(rs.getString("CLASES"));
            bean.setIdClase(rs.getString("TB_CLASE_SUB_ID_CLASE_SUB"));
            if(rs.getBlob("BASES") != null){
            bean.setBases(rs.getBlob("BASES").getBytes(1, (int)rs.getBlob("BASES").length()));
            bean.setNombases(rs.getString("NOMBREARCHIVOBASE"));
            bean.setContentTypeBases(rs.getString("EXTARCHIVOBASE"));
            }
            bean.setEstado(rs.getString("ESTADO"));
            bean.setCantResultados(rs.getInt("CANTRESULTADOS"));
            bean.setVersion(rs.getInt("VERSION"));
            return bean;
        }

    }


}
